package d0318;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;

public class AnnualMeet implements Runnable {
    int i = 1;
    int[] nums = AnnualMeet.randoms();
    public static int[] randoms() {
        int[] nums = new int[30];
        nums[0] = (int)(Math.random()*30+1);
        int index= 1;
        while(true) {
            int random = (int)(Math.random()*30+1);
            int i;
            for( i = 0; i < index; i++) {
                if(random == nums[i]) {
                    break;
                }
            }
            if(i == index) {
                nums[index++] = random;
            }
            if(index == 30) {
                break;
            }
        }

        return nums;
    }
    public void run() {
        while(i != 30) {
            synchronized (this) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(i + "号员工" + Thread.currentThread().getName() + "进入，奖牌号" + nums[i - 1]);
                if (i == 30) {
                    break;
                }
                i++;
            }
        }

    }
    public static void main(String[] args) {
        AnnualMeet annualMeet = new AnnualMeet();
        Thread t1 = new Thread(annualMeet,"前门");
        Thread t2 = new Thread(annualMeet,"后门");
        t1.start();
        t2.start();
    }
}
